package cn.lg.soar.system.monitor.controller;

import cn.lg.soar.common.model.HttpResult;
import cn.lg.soar.common.util.hardware.DiskInfo;
import cn.lg.soar.common.util.hardware.JvmInfo;
import cn.lg.soar.common.util.hardware.SystemInfo;
import cn.lg.soar.common.util.hardware.SystemUtils;
import cn.lg.soar.system.api.constant.ModuleConst;
import cn.lg.soar.system.auth.model.HardwareInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Api(tags = {"服务器信息"})
@RestController
@RequestMapping(ModuleConst.MODULE_NAME + "/server")
public class ServerController {

    @ApiOperation("硬件信息")
    @GetMapping(value = "hardware", name = "硬件信息")
    public HttpResult<HardwareInfo> hardware() {
        HardwareInfo info = new HardwareInfo();
        info.setJvmInfo(SystemUtils.getJvmInfo());
        info.setSystemInfo(SystemUtils.getSystemInfo());
        info.setDiskInfo(SystemUtils.getDiskInfo());
        info.setStartTime(SystemUtils.startTime());
        info.setDuration(SystemUtils.duration());
        return HttpResult.data(info);
    }

    @ApiOperation("JVM内存信息")
    @GetMapping(value = "jvm", name = "JVM内存信息")
    public HttpResult<JvmInfo> jvm() {
        return HttpResult.data(SystemUtils.getJvmInfo());
    }

    @ApiOperation("系统内存信息")
    @GetMapping(value = "system", name = "系统内存信息")
    public HttpResult<SystemInfo> system() {
        return HttpResult.data(SystemUtils.getSystemInfo());
    }

    @ApiOperation("内存信息")
    @GetMapping(value = "memory", name = "内存信息")
    public HttpResult<HardwareInfo> memory() {
        HardwareInfo info = new HardwareInfo();
        info.setJvmInfo(SystemUtils.getJvmInfo());
        info.setSystemInfo(SystemUtils.getSystemInfo());
        return HttpResult.data(info);
    }

    @ApiOperation("磁盘信息")
    @GetMapping(value = "disk", name = "磁盘信息")
    public HttpResult<DiskInfo[]> disk() {
        return HttpResult.data(SystemUtils.getDiskInfo());
    }

}
